我們今天來看到抽象類別跟介面的差異性吧~
學習目標: Abstract Class and Interface的概念及實務
學習難度: ☆☆☆
抽象類別是怎麼被實現的呢~
public abstract class Programmer
{
public string name { get; set; }
public abstract void coding();
public virtual void debug()
{
Console.WriteLine("I could debug");
}
}
public class UnityProgrammer:Programmer
{
public override void coding()
{
Console.WriteLine("I could used unity to develop game");
}
}
介面是怎麼被實現的呢~
public interface IProgrammer
{
public string name { get; set; }
public void coding();
}
public class UnityProgrammer: IProgrammer
{
public string name { get; set; }
public void coding()
{
Console.WriteLine("I could used unity to develop game");
}
}
參考資料:
https://www.geeksforgeeks.org/difference-between-abstract-class-and-interface-in-c-sharp/